#include <cstdlib>
#include <string>
#include <iostream>
#include <vector>
#include <climits>

using namespace std;


struct TreeNode {
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};

class Solution {
public:
	int height;
	void levelOrderBottom(TreeNode* root, vector<vector<int> >& answer, int level){
		if (root == NULL){
			return;
		}
		levelOrderBottom(root->left, answer, level+1);
		levelOrderBottom(root->right, answer, level+1);
		answer[height - level].push_back(root->val);
	}
	int treeheight(TreeNode* root){
		if (root == NULL) return 0;
		int leftH = treeheight(root->left);
		int rightH = treeheight(root->right);
		return (leftH > rightH ? leftH : rightH) + 1;
	}
	vector<vector<int> > levelOrderBottom(TreeNode *root) {
		vector<vector<int> > answer;
		int level = 1;
		height = treeheight(root);
		for (int i = 0; i < height; ++i){
			vector<int> layer;
			answer.push_back(layer);
		}
		levelOrderBottom(root, answer, level);
		return answer;
	}
};

int main(int argc, char argv){
	TreeNode node1(1), node2(2);
	node1.left = &node2;
	Solution().levelOrderBottom(&node1);
	return 0;
}